# models/auth_log.py
from datetime import datetime
from models.base import BaseModel
from models import db
import uuid


class AuthLog(BaseModel):
    __tablename__ = 'auth_logs'
    
    id = db.Column(db.String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
    user_id = db.Column(db.String(36), db.ForeignKey('users.id'), nullable=True)
    event_type = db.Column(db.String(50), nullable=False)
    ip_address = db.Column(db.String(50), nullable=False)
    user_agent = db.Column(db.String(255), nullable=True)
    timestamp = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
    
    def __repr__(self):
        return f"<AuthLog {self.event_type} by user {self.user_id} at {self.timestamp}>"